package jmine.tec.services.api;

import java.util.List;

import bancosys.tec.exception.AbstractError;
import bancosys.tec.exception.AbstractException;
import bancosys.tec.exception.AbstractRuntimeException;
import bancosys.tec.exception.LocalizedMessageHolder;
import bancosys.tec.persist.validator.ValidationException;

/**
 * Exception lancada se ocorrer algum erro durante a execucao de um servico.
 * 
 * @author Rafael Volpato (Jun 6, 2007)
 */
public class ServiceExecutionException extends AbstractException {

    private List<Throwable> causes;

    /**
     * Construtor Evite usar, mensagem pouco informativa.
     * 
     * @param cause cause
     */
    public ServiceExecutionException(Throwable cause) {
        this(ServicesAPIMessages.GENERIC_EXECUTION_ERROR.create(cause.getMessage()), cause);
    }

    /**
     * Construtor Evite usar, mensagem pouco informativa.
     * 
     * @param service o serviço que falhou.
     * @param cause cause
     */
    public ServiceExecutionException(Service<?> service, Throwable cause) {
        this(ServicesAPIMessages.GENERIC_SERVICE_EXECUTION_ERROR.create(service.getServiceName(), cause.getMessage()), cause);
    }

    /**
     * C'tor
     * 
     * @param service o serviço que falhou.
     * @param cause {@link AbstractError}
     */
    public ServiceExecutionException(Service<?> service, AbstractError cause) {
        this(ServicesAPIMessages.GENERIC_SERVICE_EXECUTION_ERROR.create(service, cause.getLocalizedMessage()), cause);
    }

    /**
     * C'tor
     * 
     * @param service o serviço que falhou.
     * @param cause {@link AbstractError}
     */
    public ServiceExecutionException(Service<?> service, ValidationException cause) {
        this(ServicesAPIMessages.GENERIC_SERVICE_EXECUTION_ERROR.create(service, cause.getLocalizedMessage()), cause);
    }

    /**
     * C'tor
     * 
     * @param service o serviço que falhou.
     * @param cause {@link AbstractError}
     */
    public ServiceExecutionException(Service<?> service, AbstractRuntimeException cause) {
        this(ServicesAPIMessages.GENERIC_SERVICE_EXECUTION_ERROR.create(service, cause.getLocalizedMessage()), cause);
    }

    /**
     * Construtor.
     * 
     * @param message message
     * @param causes lista de excecoes.
     */
    public ServiceExecutionException(LocalizedMessageHolder message, List<Throwable> causes) {
        super(message);
        this.causes = causes;
    }

    /**
     * @return lista de excecoes associadas.
     */
    public List<Throwable> getCauses() {
        return this.causes;
    }

    /**
     * Construtor
     * 
     * @param messageHolder messageHolder
     * @param cause cause
     */
    public ServiceExecutionException(LocalizedMessageHolder messageHolder, Throwable cause) {
        super(messageHolder, cause);
    }

    /**
     * Construtor
     * 
     * @param messageHolder messageHolder
     */
    public ServiceExecutionException(LocalizedMessageHolder messageHolder) {
        super(messageHolder);
    }

    /**
     * @param key key
     * @param arguments arguments
     */
    @Deprecated
    public ServiceExecutionException(String key, Object... arguments) {
        super(key, arguments);
    }

    /**
     * @param key key
     * @param cause cause
     * @param arguments arguments
     */
    @Deprecated
    public ServiceExecutionException(String key, Throwable cause, Object... arguments) {
        super(key, cause, arguments);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getBundleBaseName() {
        return "jmine-tec-services-api-messages";
    }
}
